<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>农家乐</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/picker.css" />
		<link rel="stylesheet" href="../css/poppicker.css" />
		<link rel="stylesheet" type="text/css" href="../css/style.css" />
		<link rel="stylesheet" type="text/css" href="../css/datepicker3.css" />
		<link rel="stylesheet" href="../css/member.css" />
		
	</head>

	<body>
		<header class="mui-bar mui-bar-nav public-color">
			<a id="shan" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">农家乐</h1>
		</header>
		<div class="mui-content address_content">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>服务项目：</label>
					<input type="text" id="price" class="mui-input-group" placeholder="请输入服务项目">
				</div>
				<div class="mui-input-row">
					<label>原价：</label>
					<input type="text" id="price" class="mui-input-group" placeholder="请输入原价">
				</div>
				<div class="mui-input-row">
					<label>会员价：</label>
					<input type="text" id="price" class="mui-input-group" placeholder="请输入会员价">
				</div>
				<div class="mui-input-row">
					<label>简介：</label>
					<input type="text" id="price" class="mui-input-group"  placeholder="请输入简介">
				</div>
				<div class="mui-input-row">
					<label>图片：</label>
					<input type="text" id="price" class="mui-input-group" placeholder="请输入图片">
				</div>

			</form>
			<div class="address_mor clearfix">
				<label class="col-sm-3 control-label">图文详情：</label>
				<strong>默认第一张主图</strong>
				<form class="mui-input-group gerenzl_group">
					<div class="gerenzl_top img-click">
						<div class="actions">
							<button class="file-btn" style="width: 60%; height: 30px;">
				               <span style="font-size: 12px;width: 60%;">上传图片</span>
				                <input type="file" id="upload" value="选择图片文件" multiple/>
				           </button>
							<hr>
							<div id="img_list" class="img_list">

							</div>
						</div>

					</div>

				</form>

				<div class="gerzl_btn" id="btn" onclick="func1()">
					<a href="#">发布</a>
				</div>
			</div>
			<input type="hidden" id='order_ids'>
			<script type="text/javascript" src="../js/jquery.min.js"></script>
			<script type="text/javascript" src="../js/bootstrap-datepicker.js"></script>
			<script src="../js/layer/layer.min.js"></script>
			<script src="../js/mui.min.js"></script>
			<script src="../js/castapp.js"></script>
			<script src="../js/picker.js"></script>
			<script src="../js/poppicker.js"></script>
			<script src="../js/city.data-3.js"></script>
			<script src="../js/app.js"></script>
			<script src="../js/ueditor/ueditor.config.js" type="text/javascript"></script>
			<script src="../js/ueditor/ueditor.all.js" type="text/javascript"></script>

			<script>
				//编辑器
				var member = JSON.parse(localStorage.getItem('member'));
				$(function() {
					//dlpd();
					ca.init();
					var dis = ca.id('district');
					dis.addEventListener('tap', function() {
						//三级组合
						castapp.combinationSelect(3, cityData3, function(arr) {
							dis.value = arr;
						});
					});

					$(".datetimepicker").datepicker({
						language: "zh-CN",
						autoclose: true, //选中之后自动隐藏日期选择框
						clearBtn: true, //清除按钮
						todayBtn: true, //今日按钮
						format: "yyyy-mm-dd" //日期格式，详见 http://bootstrap-datepicker.readthedocs.org/en/release/options.html#format
					});
					$('#upload').on('change', function() {
						readFile(this, "thumb", 1, 10);
					});

					//获取分类
					$.ajax({
						type: "post",
						url: APP.api_url + "goods/get_type",
						data: {},
						dataType: 'jsonp',
						success: function(data) {
							var type = data.list;
							for(var i = 0; i < type.length; i++) {
								$('#type').append('<option value=' + type[i]['id'] + '>' + type[i]['typename'] + '</option>');
							}

						},

					});

				});

				$("#shan").click(function() {
					location.href = "spedit.html";
				});
				//获取传过来的图片
				function func1() {
					var x = document.getElementsByName("pic_d");
					var pic_d = "";
					var images = "";
					for(var i = 0; i < x.length; i++) {
						if(i == 0) {
							images += x[i].value;
							pic_d += x[i].value;
						} else {
							pic_d += '@' + x[i].value;
						}

					}

					if($("#name").val() == '') {
						layer.msg('产品名称不能为空', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					if($("#type").val() == '') {
						layer.msg('请选择分类', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					if($('#price').val() == '') {
						layer.msg('售价不能为空', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					if($('#district').val() == '') {
						layer.msg('地址不能为空', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					if($('#cr_time').val() == '') {
						layer.msg('生产时间不能为空', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					if($('#num').val() == '') {
						layer.msg('预产量不能为空', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					if(pic_d == "") {
						layer.msg('请上传图片', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					$.ajax({
						type: "post",
						url: APP.api_url + "goods/cre_goods",
						data: {
							id: member['id'],
							name: $('#name').val(),
							type_id: $("#type").val(),
							price: $('#price').val(),
							address: $('#district').val(),
							cr_time: $('#cr_time').val(),
							num: $('#num').val(),
							img: pic_d,
							images: images,
							unit: $('#unit').val()
						},
						dataType: 'jsonp',
						success: function(data) {
							layer.msg(data.msg, { icon: 1, time: 1500, shade: 0.1 }, function(index) {
								window.location.href = "../goods/spedit.html";
							});
						},

					});

				}
			</script>